home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / qltk / debugwindow.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  7KB  |  141 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. import sys
  6. import time
  7. import traceback
  8. import platform
  9. from gi.repository import Gtk
  10. from quodlibet import const
  11. from quodlibet import util
  12. from quodlibet.util.path import unexpand, mkdir
  13. from quodlibet.util import connect_obj
  14. old_hook = sys.excepthook
  15.  
  16. class ExceptionDialog(Gtk.Window):
  17.     running = False
  18.     instance = None
  19.     DUMPDIR = os.path.join(const.USERDIR, 'dumps')
  20.     
  21.     def from_except(Kind, *args):
  22.         mkdir(Kind.DUMPDIR)
  23.         dump = os.path.join(Kind.DUMPDIR, time.strftime('Dump_%Y%m%d_%H%M%S.txt'))
  24.         minidump = os.path.join(Kind.DUMPDIR, time.strftime('MiniDump_%Y%m%d_%H%M%S.txt'))
  25.         full_args = list(args) + [
  26.             dump,
  27.             minidump]
  28.         Kind._ExceptionDialog__dump(*full_args)
  29.         if not Kind.running:
  30.             Kind.running = True
  31.             Kind.instance = Kind(*full_args)
  32.         return Kind.instance
  33.  
  34.     from_except = classmethod(from_except)
  35.     
  36.     def excepthook(Kind, *args):
  37.         instance = Kind.from_except(*args)
  38.         instance.show()
  39.         old_hook(*args)
  40.  
  41.     excepthook = classmethod(excepthook)
  42.     
  43.     def __dump(self, Kind, value, trace, dump, minidump):
  44.         import mutagen as mutagen
  45.         logging = logging
  46.         import quodlibet.util
  47.         dumpobj = file(dump, 'w')
  48.         minidumpobj = file(minidump, 'w')
  49.         header = 'Quod Libet %s\nMutagen %s\nPython %s %s\nPlatform %s' % (const.VERSION, mutagen.version_string, sys.version, sys.platform, platform.platform())
  50.         minidump_data = '=== SYSTEM INFORMATION:\n%s\n\n=== STACK TRACE\n%s\n\n' % (header, '\n'.join(traceback.format_exception(Kind, value, trace)))
  51.         print >>dumpobj, minidump_data
  52.         print >>minidumpobj, minidump_data
  53.         minidumpobj.close()
  54.         for logname in logging.names():
  55.             print >>dumpobj, '=== LOG: %r\n%s\n\n' % (logname, '\n'.join(logging.contents(logname)[-50:]))
  56.         
  57.         dumpobj.close()
  58.  
  59.     __dump = classmethod(__dump)
  60.     
  61.     def __init__(self, Kind, value, traceback, dump, minidump):
  62.         Gtk.Window.__init__(self)
  63.         self.set_default_size(400, 400)
  64.         self.set_border_width(12)
  65.         self.set_title(_('Error Occurred'))
  66.         desc = _('An exception has occured in Quod Libet. A dump file has been saved to <b >%s</b> that will help us debug the crash. Please file a new issue at http://code.google.com/p/quodlibet/issues/list and attach this file or include its contents. This file may contain some identifying information about you or your system, such as a list of recent files played. If this is unacceptable, send <b>%s</b> instead with a description of what you were doing.') % (unexpand(dump), unexpand(minidump))
  67.         suggestion = _('Quod Libet may now be unstable. Closing it and restarting is recommended. Your library will be saved.')
  68.         label = Gtk.Label(label = desc + '\n\n' + suggestion)
  69.         label.set_selectable(True)
  70.         label.set_use_markup(True)
  71.         label.set_line_wrap(True)
  72.         box = Gtk.VBox(spacing = 6)
  73.         buttons = Gtk.HButtonBox()
  74.         view = Gtk.TreeView()
  75.         sw = Gtk.ScrolledWindow()
  76.         sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.ALWAYS)
  77.         sw.set_shadow_type(Gtk.ShadowType.IN)
  78.         sw.add(view)
  79.         model = Gtk.ListStore(str, str, int)
  80.         self._ExceptionDialog__fill_list(view, model, value, traceback)
  81.         view.set_model(model)
  82.         cancel = Gtk.Button(stock = Gtk.STOCK_CANCEL)
  83.         close = Gtk.Button(stock = Gtk.STOCK_QUIT)
  84.         buttons.pack_start(close, True, True, 0)
  85.         buttons.pack_start(cancel, True, True, 0)
  86.         box.pack_start(label, False, True, 0)
  87.         box.pack_start(sw, True, True, 0)
  88.         box.pack_start(buttons, False, True, 0)
  89.         self.add(box)
  90.         self.connect('destroy', self._ExceptionDialog__destroy)
  91.         connect_obj(cancel, 'clicked', Gtk.Window.destroy, self)
  92.         close.connect('clicked', (lambda : Gtk.main_quit()))
  93.         self.get_child().show_all()
  94.         
  95.         def first_draw(*args):
  96.             filename = unexpand(dump)
  97.             offset = label.get_text().decode('utf-8').find(filename)
  98.             label.select_region(offset, offset + len(filename))
  99.             self.disconnect(self._ExceptionDialog__draw_id)
  100.  
  101.         self._ExceptionDialog__draw_id = self.connect('draw', first_draw)
  102.  
  103.     
  104.     def __stack_row_activated(self, view, path, column):
  105.         model = view.get_model()
  106.         filename = model[path][0]
  107.         line = model[path][2]
  108.         util.spawn([
  109.             'sensible-editor',
  110.             '+%d' % line,
  111.             filename])
  112.  
  113.     
  114.     def __fill_list(self, view, model, value, trace):
  115.         for frame in reversed(traceback.extract_tb(trace)):
  116.             (filename, line, function, text) = frame
  117.             model.append(row = [
  118.                 filename,
  119.                 function,
  120.                 line])
  121.         
  122.         view.connect('row-activated', self._ExceptionDialog__stack_row_activated)
  123.         
  124.         def cdf(column, cell, model, iter, data):
  125.             cell.set_property('markup', '<b>%s</b> line %d\n\t%s' % (util.escape(model[iter][1]), model[iter][2], util.escape(unexpand(model[iter][0]))))
  126.  
  127.         render = Gtk.CellRendererText()
  128.         col = Gtk.TreeViewColumn(str(value).replace('_', '__'), render)
  129.         col.set_cell_data_func(render, cdf)
  130.         col.set_visible(True)
  131.         col.set_expand(True)
  132.         view.append_column(col)
  133.  
  134.     
  135.     def __destroy(self, window):
  136.         type(self).running = False
  137.         type(self).instance = None
  138.         window.destroy()
  139.  
  140.  
  141.